package top.zuli.package01.class15;

import org.junit.Test;

public class Demo7 {
    @Test
    public void StringBufferMethodTest(){
        //创建实例
        StringBuffer sb = new StringBuffer();
        //拼接字符串
        sb.append(1);
        sb.append(true);
        sb.append("hello");
        System.out.println(sb);
        //从0下标删除到5下标,包含开始下标，不包含结束下标
        sb.delete(1,5);
        System.out.println(sb);
        //替换内容,包含开始，不包含结束下标
        sb.replace(1,5,"aaa");
        System.out.println(sb);
        //插入指定内容
        sb.insert(1,"hello");
        System.out.println(sb);
        //字符串反转
        sb.reverse();
        System.out.println(sb);
        //截取字符串，返回新的字符串
        String result = sb.substring(0, 3);
        System.out.println(result);
        //将StringBuffer转为String类型
        System.out.println(sb.toString());
    }
}

/*
public class Demo7 {
    @Test
    public void StringBufferMethodTest(){
        StringBuffer sb = new StringBuffer();
        sb.append(1);
        sb.append(true);
        sb.append("hello");
        System.out.println(sb);
        sb.delete(1,5);
        System.out.println(sb);
        sb.replace(1,5,"aaa");
        System.out.println(sb);
        sb.insert(1,"hello");
        System.out.println(sb);
        sb.reverse();
        System.out.println(sb);
        String result = sb.substring(0, 3);
        System.out.println(result);
        System.out.println(sb.toString());
    }
}
*/
